<template>
  <el-table :data="list" style="width: 100%;">
    <el-table-column label="标题" min-width="200" prop="title">
    </el-table-column>
    <el-table-column label="工单类型" width="195" align="center" prop="type.name">
    </el-table-column>
    <el-table-column label="提交人" width="195" align="center" prop="applicant.name">
    </el-table-column>
    <el-table-column label="状态" width="100" align="center">
      <template slot-scope="scope">
        <el-tag :type="scope.row.status.id | statusFilter"> {{ scope.row.status.name }}</el-tag>
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
import { getWorkOrderList } from '@/api/workorder'

export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        '2': 'success',
        '3': 'warning',
        '1': 'primary',
        '0': 'info'
      }
      return statusMap[status.toString()]
    },
    orderNoFilter(str) {
      return str.substring(0, 30)
    }
  },
  data() {
    return {
      list: null
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      getWorkOrderList({ page_size: 5, page: 1 }).then(res => {
        this.list = res.results
      })
    }
  }
}
</script>
